//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.member;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.MemberContractDao;
import com.aidong.model.wills.ContractInfo;
import com.aidong.util.ExportXls;
import com.aidong.web.controller.BaseController;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"memberContractQuery"})
public class MemberContractQueryController extends BaseController {
    @Resource
    MemberContractDao memberContractDao;

    public MemberContractQueryController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return (new ModelAndView("member/contractquery/list")).addObject("dt1", sdf.format(new Date(System.currentTimeMillis() - 86400000L))).addObject("dt2", sdf.format(new Date()));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "cardCode",required = false) String cardCode, @RequestParam(value = "contractCode",required = false) String contractCode, @RequestParam(value = "name",required = false) String name, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "c.shopCode", shopCode);
        if(!this.chkNull(cardCode) || !this.chkNull(name) || !this.chkNull(contractCode)) {
            cd.eq("m.cardCode", cardCode);
            cd.eq("m.chName", name);
            cd.eq("c.contractCode", contractCode);
            this.memberContractDao.queryPageList2(pg, cd);
        }

        ModelAndView mv = new ModelAndView("member/contractquery/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "cardCode",required = false) String cardCode, @RequestParam(value = "contractCode",required = false) String contractCode, @RequestParam(value = "name",required = false) String name, HttpServletResponse response) {
        try {
            Pagination e = new Pagination(1, '\uea60');
            e.setPage(Integer.valueOf(1), Integer.valueOf(1));
            ConditionMap cd = new ConditionMap();
            this.addConditionShopCode(cd, "c.shopCode", shopCode);
            if(this.chkNull(cardCode) && this.chkNull(name) && this.chkNull(contractCode)) {
                e.setResultList(new ArrayList());
            } else {
                cd.eq("m.cardCode", cardCode);
                cd.eq("m.chName", name);
                cd.eq("c.contractCode", contractCode);
                this.memberContractDao.queryPageList2(e, cd);
            }

            ExportXls xls = new ExportXls(response, "次卡剩余次数查询", "次卡剩余次数查询");
            xls.addHead(new String[]{"卡号", "会员号", "会员姓名", "合同号", "卡种", "总次数", "剩余次数", "会籍起日", "会籍迄日"});
            xls.setWidth(new int[]{10, 20, 10, 15, 30, 10, 10, 12, 12});
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Iterator i$ = e.getResultList().iterator();

            while(i$.hasNext()) {
                ContractInfo contract = (ContractInfo)i$.next();
                xls.addRow(new Object[]{contract.getCardCode(), contract.getMemberCode(), contract.getMemberName(), contract.getContractCode(), contract.getCardType() + " - " + this.cache.getValue("cardType", contract.getCardType()), this.chkNullZ(contract.getTotalCount())?"-":contract.getTotalCount(), this.chkNullZ(contract.getRestCount())?"-":contract.getRestCount(), sdf.format(contract.getBeginTime()), sdf.format(contract.getEndTime())});
            }

            xls.close();
            this.addUserLog("导出次卡剩余次数查询", e.getResultList().size() + "条记录");
        } catch (Exception var13) {
            this.log.error("import", var13);
        }

        return null;
    }
}
